<?php
require_once 'includes/config.php';
require_once 'includes/functions.php';
require_once 'includes/class.phpmailer.php';
if(empty($_SESSION['userIdForgotPasswordSess']) && $_SESSION['userPasswordForgotPasswordSess'])
header("Location:index.php?notFound");
if(!empty($_POST['submit']))
{
$userId=$_SESSION['userIdForgotPasswordSess'];
$newPassword=$_REQUEST['newPassword'];
$sqlUpdPwd="UPDATE tbl_users SET password='$newPassword' WHERE user_id=$userId";
$rstUpdPwd=mysql_query($sqlUpdPwd);
$noUpdPwd=mysql_affected_rows();
if($noUpdPwd>0)
{
 	$sqlSelUsr = "select * from tbl_users where user_id='".$userId."'";
	$rstSelUsr = mysql_query($sqlSelUsr) or die(mysql_error());
	$noSelUsr = @mysql_num_rows($rstSelUsr);
	if($noSelUsr>0)
	{
		$rowSelUsr=mysql_fetch_array($rstSelUsr);
		$firstName=$rowSelUsr['first_name'];
		$lastName=$rowSelUsr['last_name'];
		$userName=$rowSelUsr['username'];
		$email=$rowSelUsr['email'];
		$msg="<table width='100%' border='0' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px; line-height:25px'>
  <tr>
    <td width='18%' height='41'><table width='100%' border='0'>
      <tr>
        <td width='19%' height='68'><img src='http://localhost/projects/swapen_new/images/logo.gif' width='208' height='83'></td>
        <td width='81%'>Swapen sent this message to <b>".$firstName." ".$lastName."  ( ".$userName." )</b> <br>
Your registered name is included to show this message originated from Swapen. </td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height='32' colspan='2' style='font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;color:#FFFFFF;background-color:#0FB6FA;'><b>&nbsp;&nbsp;Complete your Swapen registration</b></td>
  </tr>
  <tr>
    <td>
      <table width='100%' border='0'>
        <tr>
          <td width='71%' height='124'><p><b>Hi ".$firstName." ".$lastName." </b>, </p>
          <p>This is a courtesy notice to let you know that your eBay password has been changed. No response is needed. </p>
          <div><br>
          If you or anyone with authorized access to your account did not make this change, please send an email to <a href='mailto:password@swapen.com' target='_blank'>password@swapen.com</a>. </div></td>
        </tr>
      </table>
    </td>
  </tr>
</table>
";
		$mail = new PHPMailer(); // defaults to using php "mail()"
	  	$mail->MsgHTML($msg);
		$mail->From       = "mail@swapen.com";
		$mail->FromName   = "Swapen.com";
		$mail->Subject    = "Swapen Change Password Confirmation";
		$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
		$mail->AddAddress($email, $firstName);
		$mail->Send();
		}
  	$msg = "<font face=verdana size=2 color='#005B00'><b>Your password changed successfully.<a href='index.php?signin'>Signin here</a> to continue.</b></font>";
  }
else
  $msg = "<font face=verdana size=2 color='#FF0000'><b>Invalid answers, Please enter valid answers for below questions atleast two or more</b></font>";
}
?>
<div class="fulldiv" style="width:700px;">

 <div class="fulldiv" style="margin:10px 0px 0px 0px;">
	
<div style="float:left; margin:0px 10px 0px 10px;"><strong class="orangehead">Confirm your identity to reset password </strong></div>

<div class="fullbox_top">&nbsp;</div>
	<div class="fullbox_repeat">
<form name="frmPasswordChange" id="frmPasswordChange" method="post" action="<?php echo $_SERVER['php_self']?> " onSubmit="return validatePasswordChange()">
<table width="100%" border="0" class="contentForm"  cellpadding="0" cellspacing="0">
  <tr>
    <td width="35%" class="contentHeader"><h2>Change your Password</h2></td>
  </tr>
  <tr>
    <td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="2%"></td>
    <td width="98%"  height="10"></td>
  </tr>
  <tr>
    <td></td>
    <td  height="16"><div id="messageArea">
      <?php if(isset($msg))
											echo "<b>".$msg."</b>";
										
		?>
    </div></td>
  </tr>
  <tr>
    <td></td>
    <td  height="10"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div id="lblNewPassword">New password</div>
        <input type="password" name="newPassword" id="newPassword"></td>
  </tr>
  <tr>
    <td></td>
    <td  height="10"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><div id="lblNewPasswordAgain">Re-enter new password</div>
        <input type="password" name="newPasswordAgain" class="inputbg" id="newPasswordAgain">    </td>
  </tr>
  <tr>
    <td></td>
    <td  height="10"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="submit" id="submit" class="inputbg" value="Submit" class="sbmt_btn" /></td>
  </tr>
  <tr>
    <td></td>
    <td  height="10"></td>
  </tr>
</table>
</td>
</tr>
</table>
</form>
</div>
<div class="fullbox_bot">&nbsp;</div>

</div>

</div>
<br />